package com.tudouji.project.customer.controller;

import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.framework.web.page.TableDataInfo;
import com.tudouji.project.customer.domain.Addresrecord;
import com.tudouji.project.customer.service.IAddresrecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地址记录Controller
 *
 * @author tudouji
 * @date 2022-09-29
 */
@RestController
@RequestMapping("/customer/addresrecord")
public class AddresrecordController extends BaseController
{
    @Autowired
    private IAddresrecordService addresrecordService;

    /**
     * 查询地址记录列表
     */
    @PreAuthorize("@ss.hasPermi('customer:addresrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(Addresrecord addresrecord)
    {
        startPage();
        List<Addresrecord> list = addresrecordService.selectAddresrecordList(addresrecord);
        return getDataTable(list);
    }

    /**
     * 导出地址记录列表
     */
    @PreAuthorize("@ss.hasPermi('customer:addresrecord:export')")
    @Log(title = "地址记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Addresrecord addresrecord)
    {
        List<Addresrecord> list = addresrecordService.selectAddresrecordList(addresrecord);
        ExcelUtil<Addresrecord> util = new ExcelUtil<Addresrecord>(Addresrecord.class);
        return util.exportExcel(list, "addresrecord");
    }

    /**
     * 获取地址记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:addresrecord:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(addresrecordService.selectAddresrecordById(guid));
    }

    /**
     * 新增地址记录
     */
    @Log(title = "地址记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Addresrecord addresrecord)
    {

        return toAjax(addresrecordService.insertAddresrecord(addresrecord));
    }

    /**
     * 修改地址记录
     */
    @PreAuthorize("@ss.hasPermi('customer:addresrecord:edit')")
    @Log(title = "地址记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Addresrecord addresrecord)
    {
        return toAjax(addresrecordService.updateAddresrecord(addresrecord));
    }

    /**
     * 删除地址记录
     */
    @PreAuthorize("@ss.hasPermi('customer:addresrecord:remove')")
    @Log(title = "地址记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(addresrecordService.deleteAddresrecordByIds(guids));
    }

    /**
     * 查询客户地址记录
     */
    @GetMapping("/findAddress")
    public TableDataInfo findAddress(String customerid)
    {
        List<Addresrecord> list = addresrecordService.selectAddresrecordListByCustomer(customerid);
        return getDataTable(list);
    }
}
